import axios from 'axios'
import { loginUrl,regUrl } from '../../baseUrl/index'
import ss from '../../Plug/session'
import qs from 'qs'
let state={
    
}

let mutations={}

let actions={
    login({state},form){
        return new Promise((resolve,reject)=>{
            axios({
                url:loginUrl,
                method:'post',
                data:qs.stringify(form)
            }).then((data)=>{
                if(data.data.success){
                    ss.save(data.data.data)
                    resolve()
                }else{
                    alert('用户名或密码错误')
                }
            })
        })
    },
    reg({state},form){
        return new Promise((resolve,reject)=>{
            axios({
                url:regUrl,
                method:'post',
                data:form
            }).then((data)=>{
                if(data.data){
                    resolve()
                }
            })
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}